import { HttpClient } from "@angular/common/http";
import { Component, OnInit } from "@angular/core";
import { NavController } from "@ionic/angular";

@Component({
  selector: "app-delect",
  templateUrl: "./delect.page.html",
  styleUrls: ["./delect.page.scss"],
})
export class DelectPage implements OnInit {
  constructor(public router: NavController, public http: HttpClient) {}
  res: Result;

  delect(title) {
    let url = "http://xiaoshuogebed.applinzi.com/delete_book?title=" + title;
    this.http.get(url).subscribe((res) => {
      let book_url = "http://xiaoshuogebed.applinzi.com/bookrack";
      this.http.get(book_url).subscribe((res: Result) => {
        this.res = res;
        if (this.res.results.length == 0) {
          this.back();
        }
      });
    });
  }
  back() {
    window.location.replace("tabs/tab2");
  }
  ngOnInit(): void {
    let url = "http://xiaoshuogebed.applinzi.com/bookrack";

    this.http.get(url).subscribe((res: Result) => {
      this.res = res;
    });
  }
}
interface Result {
  code: number;
  message: string;
  results: Results[];
}
interface Results {
  bid: number;
  title: string;
  cover: string;
}
